package com.vans.micro.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.vans.micro.order.entity.OrderInfo;
import com.vans.micro.order.mapper.OrderInfoMapper;
import com.vans.micro.order.service.OrderInfoService;
import order.OrderInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author QXY
 * @since 2020-10-24
 */
@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderInfoMapper mapper;

    public OrderInfoVO getByUserId(Integer userId) {

//        throw new RuntimeException("异常！");
        QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(OrderInfo::getUserId, userId);
        OrderInfo order = mapper.selectOne(wrapper);
        return toVO(order);
    }

    /**
     * 返回VO
     * @param order
     * @return
     */
    private OrderInfoVO toVO(OrderInfo order) {
        OrderInfoVO orderInfoVO = new OrderInfoVO();
        orderInfoVO.setId(order.getId());
        orderInfoVO.setUserId(order.getUserId());
        orderInfoVO.setBatchId(order.getBatchId());
        orderInfoVO.setDsp(order.getDsp());
        return orderInfoVO;
    }
}
